import { Api } from '@/api'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useInformationStore = defineStore('information', () => {
  const categories = ref<Record<string, Eps.DocumentService.GetCategories[0]>>(null!)
  const setCategories = () => {
    Api.DocumentService.GetCategories().then((res) => {
      categories.value = res.reduce((acc, cur) => {
        acc[cur?.Data?.Tag ?? ''] = cur
        return acc
      }, {} as Record<string, Eps.DocumentService.GetCategories[0]>)
    })
  }
  return {
    categories,
    setCategories,
  }
})
